/*
 * 易族智汇（北京）科技有限公司 版权所有。
 * 未经许可，您不得使用此文件。
 * 官方地址：www.javamall.com.cn
 */
package com.enation.app.javashop.core.client.fallback.promotion;

import com.enation.app.javashop.core.client.feignimpl.promotion.CouponClientFeignImpl;
import com.enation.app.javashop.core.handler.BaseFallbackFactory;
import com.enation.app.javashop.model.promotion.coupon.dos.CouponDO;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fk
 * @version v2.0
 * @Description: 优惠券client断路器
 * @date 2018/9/27 14:40
 * @since v7.0.0
 */
@Component
public class CouponClientFallbackFactory extends BaseFallbackFactory<CouponClientFeignImpl> implements FallbackFactory {


    @Override
    protected CouponClientFeignImpl fallback() {
        return new CouponClientFallback();
    }

    /**
     * @author fk
     * @version v2.0
     * @Description: 优惠券client断路器
     * @date 2018/9/27 14:40
     * @since v7.0.0
     */
    @Component
    public static class CouponClientFallback implements CouponClientFeignImpl {

        protected final Log logger = LogFactory.getLog(this.getClass());

        @Override
        public CouponDO getModel(Long id) {
            if (logger.isErrorEnabled()) {
                logger.error("获取优惠券ID为" + id + "信息发生错误");
            }
            return new CouponDO();
        }

        @Override
        public void addReceivedNum(Long couponId) {
            if (logger.isErrorEnabled()) {
                logger.error("优惠券ID为" + couponId + "的优惠券新增加被领取数量发生错误");
            }
        }

        @Override
        public void addUsedNum(Long id) {
            if (logger.isErrorEnabled()) {
                logger.error("增加优惠价使用数量发生错误");
            }
        }

        @Override
        public List<CouponDO> getList(Long sellerId) {
            if (logger.isErrorEnabled()) {
                logger.error("获取优惠券列表发生错误");
            }
            return new ArrayList<>();
        }

        @Override
        public void editCouponShopName(Long shopId, String shopName) {
            if (logger.isErrorEnabled()) {
                logger.error("修改店铺id为" + shopId + "的优惠券名称修改发生错误");
            }
        }
    }
}
